/**
 * @Title: FuncServiceImpl
 * @Package cn.com.yiqi.wsc.service.func.impl
 * @Description: TODO
 * Copyright: Copyright (c) 2016
 * Company: 成都壹柒互动科技有限公司
 * @author 会员系统组-胥钰淋
 * @date 2017/2/15 11:39
 * @version V1.0
 */
package cn.com.yiqi.wsc.service.function.impl;

import cn.com.yiqi.wsc.common.BaseCriteria;
import cn.com.yiqi.wsc.common.Result;
import cn.com.yiqi.wsc.common.ResultStatusEnum;
import cn.com.yiqi.wsc.dao.func.FuncDao;
import cn.com.yiqi.wsc.dao.func.FuncGroupDao;
import cn.com.yiqi.wsc.dao.func.FunctionDao;
import cn.com.yiqi.wsc.entity.func.FuncEntity;
import cn.com.yiqi.wsc.entity.func.FuncGroupEntity;
import cn.com.yiqi.wsc.entity.func.Function;
import cn.com.yiqi.wsc.service.func.dataobject.FuncTreeNodeDO;
import cn.com.yiqi.wsc.service.function.FunctionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 会员系统组-胥钰淋
 * @ClassName: FuncServiceImpl
 * @Description: TODO
 * @date 2017/2/15 11:39
 */
@Service
public class FunctionServiceImpl implements FunctionService {
    @Autowired
    private FunctionDao functionDao;


    @Override
    public Result getPageList(BaseCriteria criteria) {

        Result result = new Result();
        result.setStatus(ResultStatusEnum.操作成功.getCode());

        PageHelper.startPage(criteria.getCurrentPage(), criteria.getPageSize());
        PageHelper.orderBy("v_code ASC");
        PageInfo<Function> functionPageInfo = new PageInfo<>(functionDao.pageList(criteria));
        result.putData("list", functionPageInfo.getList());
        result.putData("total", functionPageInfo.getTotal());

        return result;
    }

    @Override
    public Result getAll(BaseCriteria criteria) {

        Result result = new Result();
        result.setStatus(ResultStatusEnum.操作成功.getCode());
        
        PageHelper.orderBy("d_insert_time DESC");
        PageInfo<Function> functionPageInfo = new PageInfo<>(functionDao.pageList(criteria));
        result.putData("list", functionPageInfo.getList());
        result.putData("total", functionPageInfo.getTotal());

        return result;
    }

    @Override
    public Result insert(Function function) {

        Result result = new Result();
        result.setStatus(ResultStatusEnum.操作成功.getCode());
        functionDao.insert(function);

        return result;
    }

    @Override
    public Result update(Function function) {

        Result result = new Result();
        result.setStatus(ResultStatusEnum.操作成功.getCode());
        functionDao.update(function);

        return result;
    }

    @Override
    public Result delete(Function function) {

        Result result = new Result();
        result.setStatus(ResultStatusEnum.操作成功.getCode());
        functionDao.delete(function);

        return result;
    }
}
